﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VerifyArgs;


namespace Corvus.Infrastructure
{
    public class Logger : ILogger
    {

        public void Log(Type loggingType, string loggerName, LogLevel level, IFormatProvider formatter, string message, params object[] args)
        {
            Verify.Args(new { loggingType }).NotNull();
            Verify.Args(new { message }).NotNullOrEmpty();
            formatter = formatter ?? System.Globalization.CultureInfo.InvariantCulture;
            if (string.IsNullOrEmpty(loggerName)) loggerName = loggingType.FullName;
            var logger = NLog.LogManager.GetLogger(loggerName);
            if (logger == null) return;
            logger.Log(level.ToNLogLevel(), string.Format(formatter, message, args));
        }


        public void Log(Type loggingType, string loggerName, LogLevel level, Exception exception, IFormatProvider formatter, string message, params object[] args)
        {
            Verify.Args(new { loggingType }).NotNull();
            Verify.Args(new { exception }).NotNull();
            Verify.Args(new { message }).NotNullOrEmpty();
            formatter = formatter ?? System.Globalization.CultureInfo.InvariantCulture;
            if (string.IsNullOrEmpty(loggerName)) loggerName = loggingType.FullName;
            var logger = NLog.LogManager.GetLogger(loggerName);
            if (logger == null) return;
            logger.LogException(level.ToNLogLevel(), string.Format(formatter, message, args), exception);
        }

        public void Log(Type loggingType, LogLevel level, IFormatProvider formatter, string message, params object[] args)
        {
            Log(loggingType, string.Empty, level, formatter, message, args);
        }

        public void Log(Type loggingType, LogLevel level, Exception exception, IFormatProvider formatter, string message, params object[] args)
        {
            Log(loggingType, string.Empty, level, exception, formatter, message, args);
        }

        public void Log(Type loggingType, LogLevel level, string message, params object[] args)
        {
            Log(loggingType, string.Empty, level, null, message, args);
        }

        public void Log(Type loggingType, LogLevel level, Exception exception, string message, params object[] args)
        {
            Log(loggingType, string.Empty, level, exception, null, message, args);
        }
    }
}
